#include "labcall.h"

LabCall::LabCall()
{
}
void LabCall::txt2dataV(char *dataVectorB,int indexB){                   //这里的计算公式需要随时修改

    bool gpsCache[10];
    float canshu = 100.0;

    int flagPitch,flagRoll;

    char gpsInformation[6000];

    float pitch[1000],roll[1000];

    int indexP=0,indexR=0,indexGPS=0;

    /*改变采样率只影响串口信息的采集，和时间的确定。对其他通道的信息没有影响*/

    //下面对dataVectorB中的数据提取字节到gpsCache中
    int ininin = 1;//1000
    while(ininin<indexB){
        if(dataVectorB[ininin]<1000){
            //读52个点，前50个点，每10个点取均值。舍掉后两个点
            for (int ii=1;ii<10;ii++) {
                ininin++;
                if(dataVectorB[ininin]>1000){
                    gpsCache[ii] = 1;
                }else {
                    gpsCache[ii] = 0;
                }
            }
            gpsInformation[indexGPS] = gpsCache[1]+gpsCache[2]*2+gpsCache[3]*4+gpsCache[4]*8+
                    gpsCache[5]*16+gpsCache[6]*32+gpsCache[7]*64+gpsCache[8]*128;
            indexGPS++;
        }
        ininin++;
    }

    //下面将gpsCache中的字节进行挑选，并将数据存储到pitch和roll中
    for (int indInf = 0;indInf<indexGPS;indInf++) {
        if(gpsInformation[indInf]==119){
            //校验和检查完毕
            if(gpsInformation[indInf+4]/16){
                flagPitch = -1;
            }else {
                flagPitch = 1;
            }

            if(gpsInformation[indInf+7]/16){
                flagRoll = -1;
            }else {
                flagRoll = 1;
            }

            pitch[indexP] = ((gpsInformation[indInf+4]%16)*100+gpsInformation[indInf+5]/16*10+
                    gpsInformation[indInf+5]%16+
                    (gpsInformation[indInf+6]/16*10+gpsInformation[indInf+6]%16)/canshu)*flagPitch;
            indexP++;

            roll[indexR] = ((gpsInformation[indInf+7]%16)*100+gpsInformation[indInf+8]/16*10+
                    gpsInformation[indInf+8]%16+
                    (gpsInformation[indInf+9]/16*10+gpsInformation[indInf+9]%16)/canshu)*flagRoll;
            indexR++;
            indInf+=13;
        }
    }
}
